package com.ypx.ec.product.service.impl;

import com.ypx.ec.product.dao.BrandDao;
import com.ypx.ec.product.dao.CategoryDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ypx.ec.common.utils.PageUtils;
import com.ypx.ec.common.utils.Query;

import com.ypx.ec.product.dao.CategoryBrandRelationDao;
import com.ypx.ec.product.entity.CategoryBrandRelationEntity;
import com.ypx.ec.product.service.CategoryBrandRelationService;


@Service("categoryBrandRelationService")
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {
    @Autowired
    CategoryDao categoryDao;
    @Autowired
    BrandDao brandDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CategoryBrandRelationEntity> page = this.page(
                new Query<CategoryBrandRelationEntity>().getPage(params),
                new QueryWrapper<CategoryBrandRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void saveDetail(CategoryBrandRelationEntity categoryBrandRelation) {
        Long catelogId=categoryBrandRelation.getCatelogId();
        Long brandId=categoryBrandRelation.getBrandId();
        categoryBrandRelation.setCatelogName(categoryDao.selectById(catelogId).getName());
        categoryBrandRelation.setBrandName(brandDao.selectById(brandId).getName());
        baseMapper.insert(categoryBrandRelation);

    }

    @Override
    public void update(Long brandId, String name) {
        QueryWrapper<CategoryBrandRelationEntity> queryWrapper=new QueryWrapper();
        CategoryBrandRelationEntity categoryBrandRelationEntity=new CategoryBrandRelationEntity();
        categoryBrandRelationEntity.setBrandId(brandId);
        categoryBrandRelationEntity.setBrandName(name);
        queryWrapper.eq("brand_id",brandId);
        baseMapper.update(categoryBrandRelationEntity,queryWrapper);


    }

    @Override
    public void updateCatelog(Long catlogId, String name) {
        QueryWrapper<CategoryBrandRelationEntity> queryWrapper=new QueryWrapper();
        CategoryBrandRelationEntity categoryBrandRelationEntity=new CategoryBrandRelationEntity();
        categoryBrandRelationEntity.setCatelogId(catlogId);
        categoryBrandRelationEntity.setCatelogName(name);
        queryWrapper.eq("catelog_id",catlogId);
        baseMapper.update(categoryBrandRelationEntity,queryWrapper);
    }

}